package com.sdhs.paas.sdk.core.logger;

import java.util.concurrent.ConcurrentHashMap;

public final class LoggerFactory {

    private static ConcurrentHashMap<String, Logger> loggers = new ConcurrentHashMap<>();

    private LoggerFactory(){

    }

    private static Logger getLogger(String name){
        Logger logger;
        synchronized (LoggerFactory.class){
            logger = loggers.get(name);
            if(logger == null){
                logger = new Logger.Builder().setClassName(name).build();
                loggers.put(name, logger);
            }
        }
        return logger;
    }

    public static Logger getLogger(Class<?> clazz){
        if(clazz == null){
            clazz = LoggerFactory.class;
        }
        return getLogger(clazz.getName());
    }
}
